<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
use data\service\ConfigService;

/**
 * 根据用户ip获取用户的信息
 * @desc
 * @author 16
 * @date 2018/2/24
 */
function getUserAddressByIp(){
    $taobaoIP = 'http://ip.taobao.com/service/getIpInfo.php?ip='.request()->ip();
    $addressInfo = json_decode(file_get_contents($taobaoIP));

    return $addressInfo->data->county.'-'.$addressInfo->data->city;
}

/**
 * 获取项目所在域名以及目录
 * @desc
 * @author 16
 * @date 2018/3/21
 */
function current_domain(){
    return str_replace('index.php', '', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
//    return $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].str_replace("/index.php","",$_SERVER['DOCUMENT_URI']);
}

/**
 * 获取网站配置
 * @desc
 * @author 16
 * @date 2018/4/12
 */
function get_config($config_name=null){
    $configs = new ConfigService();
    if ($config_name) {
        return $configs->getWebInfo()[$config_name];
    } else{
        return $configs->getWebInfo();
    }
}

function get_web_info($info_name=null){
    $configs = new ConfigService();
    if ($info_name) {
        return $configs->getAuthorInfo()[$info_name];
    } else{
        return $configs->getAuthorInfo();
    }
}

